package aboutgeograph.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.maps.client.InfoWindowContent;
import com.google.gwt.maps.client.MapWidget;
import com.google.gwt.maps.client.Maps;
import com.google.gwt.maps.client.control.LargeMapControl;
import com.google.gwt.maps.client.geom.LatLng;
import com.google.gwt.maps.client.overlay.Marker;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.RootPanel;

public class Geograph implements EntryPoint {

//	public void onModuleLoad() {
//		RootPanel.get("geograph").add(buildUI(23.0098, 113.723,1000,1000));
//		
//	}
//    private MapWidget buildUI(double longitude,double latitude,int width,int height) {
//        // Open a map centered on Cawker City, KS USA
//        LatLng ruking = LatLng.newInstance(latitude,longitude);
//
//        final MapWidget map = new MapWidget(ruking, 1);
//        map.setCenter(ruking);
//        map.setPixelSize(width, height);
//        // Add some controls for the zoom level
//        map.addControl(new LargeMapControl());
//        // Add a marker
//        // Add an info window to highlight a point of interest
//        map.addOverlay(new Marker(ruking));
//        // Add an info window to highlight a point of interest
//        map.getInfoWindow().open(map.getCenter(), new InfoWindowContent("如金"));
//        return map;
//      }

	  // GWT module entry point method.
	  public void onModuleLoad() {
	   /*
	    * Asynchronously loads the Maps API.
	    *
	    * The first parameter should be a valid Maps API Key to deploy this
	    * application on a public server, but a blank key will work for an
	    * application served from localhost.
	   */
	   
	   String key="ABQIAAAAGRLQ3XddqfklLgXOJYJshhSeEttUDtmSbKnCGyWys7ljrGyGOBQg_N3q9lEoXUvHAee0jr5LcfQrHA";
	   Maps.loadMapsApi(key, "2", false, new Runnable() {
	      public void run() {
	        buildUi();
	      }
	    });
	  }

	  private void buildUi() {
	    // Open a map centered on Cawker City, KS USA
	    LatLng cawkerCity = LatLng.newInstance(23.04378, 113.69855);

	    final MapWidget map = new MapWidget(cawkerCity, 14);
//	    map.setSize("1200px","400px");
	    map.setSize(new Integer(Window.getClientWidth()).toString()+"px",new Integer(Window.getClientHeight()).toString()+"px");
	    // Add some controls for the zoom level
	    map.addControl(new LargeMapControl());

	    // Add a marker
	    map.addOverlay(new Marker(cawkerCity));

	    // Add an info window to highlight a point of interest
	    map.getInfoWindow().open(map.getCenter(),
	        new InfoWindowContent("<span style='font-size:12px;'><a href='/index.jhtml' style='color:#444444'>东莞市如金自动化设备科技有限公司<br />DongGuan Ruking Automation Equipment Technology Limited Company</a></span>"));
//
//	    final DockLayoutPanel dock = new DockLayoutPanel(Unit.PX);
//	    dock.addNorth(map, 500);

	    // Add the map to the HTML host page
	    RootPanel.get("ditu").add(map);
	  }


}